package com.intellagric.controller.portal.traceability;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.pojo.TraceProcess;
import com.intellagric.service.traceability.trace_process.ProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2019/1/13
 * @DESC： 生产流程配置管理控制
 */
@Controller
public class ProcessController {

    @Autowired
    private ProcessService processService;

    /**
     * 查询生产流程配置信息
     * @return Object
     */
    @RequestMapping("/process/{id}")
    @ResponseBody
    public TraceProcess get(@PathVariable String id) {
        return processService.getProcessById(id);
    }

    /**
     * 查询生产流程配置信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/list/{produceBatchId}")
    @ResponseBody
    public LayuiDataGridResult getList(@PathVariable String produceBatchId) {
        return processService.getProcessList(produceBatchId);
    }

    /**
     * 查询生产流程配置信息列表，并生成树形列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/tree/{templateId}")
    @ResponseBody
    public LayuiDataGridResult getTree(@PathVariable String templateId) {
        return processService.getProcessTree(templateId);
    }

    /**
     * 查询生产流程配置信息列表，并生成树形列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/tree/select/{templateId}")
    @ResponseBody
    public List<TraceProcess> getTreeSelect(@PathVariable String templateId) {
        return processService.getProcessTree(templateId).getData();
    }

    /**
     * 查询生产流程配置信息子级列表，并生成树形列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/process/tree/sub")
    @ResponseBody
    public LayuiDataGridResult getSubTree(String parentId,String produceBatchId) {
        return processService.getProcessByParentId(parentId,produceBatchId);
    }

}
